﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace FindDuplicateFile
{
    /// <summary>
    /// Interaction logic for GridFiles.xaml
    /// </summary>
    public partial class GridFiles : UserControl, INotifyPropertyChanged
    {
        public GridFiles()
        {
            this.DataContext = this;
            InitializeComponent();

            OpenFileAction = (grid) => { if (grid.CurrentFile != null) grid.CurrentFile.OpenFile(); };
            OpenDirectoryAction = (grid) => { if (grid.CurrentFile != null) grid.CurrentFile.OpenDirectory(); };
            DeleteAction = (grid) => { if (grid.CurrentFile != null) grid.CurrentFile.Delete(); };
            SelectAction = null;
            ExportExcelAction = (grid) => ExportExcel();
        }

        private void mnuOpenDirectory(object sender, RoutedEventArgs e)
        {
            if (OpenDirectoryAction != null)
                OpenDirectoryAction(this);
        }

        private void mnuOpenFile(object sender, RoutedEventArgs e)
        {
            if (OpenFileAction != null)
                OpenFileAction(this);
        }

        private void mnuDeleteFile(object sender, RoutedEventArgs e)
        {
            if (DeleteAction != null)
                DeleteAction(this);
        }

        private void mnuExportExcel(object sender, RoutedEventArgs e)
        {
            if (ExportExcelAction != null)
                ExportExcelAction(this);
        }

        private void gridFiles_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (SelectAction != null)
                SelectAction(this);

            if (OpenFileAction != null)
                OpenFileAction(this);
        }

        public void ExportExcel()
        {
            FSFileNode.ExportExcel(this.Files);
        }

        public Action<GridFiles> SelectAction { get; set; }
        public Action<GridFiles> OpenFileAction { get; set; }
        public Action<GridFiles> OpenDirectoryAction { get; set; }
        public Action<GridFiles> DeleteAction { get; set; }
        public Action<GridFiles> ExportExcelAction { get; set; }

        public List<FSFileNode> Files 
        { 
            get { return (List<FSFileNode>)GetValue(FilesProperty); }
            set { SetValue(FilesProperty, value); }
        }
        public static readonly DependencyProperty FilesProperty = DependencyProperty.Register("Files", typeof(List<FSFileNode>), typeof(GridFiles));

        public FSFileNode CurrentFile
        {
            get
            {
                return this.gridFiles.CurrentItem as FSFileNode;
            }
        }

        #region Fucking/Garbage for : INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion Fucking/Garbage for : INotifyPropertyChanged

    }
}
